package com.zy.yun.core.utils;


import com.zy.yun.base.common.RestResult;
import com.zy.yun.base.constant.ReturnCodeMsgEnum;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author: wangyanwei
 * @Date: 2019/4/13 10:25
 * @Description:
 */
@Slf4j
public class ResponseUtil {

    /**
     * 功能描述: 参数为null 时，返回提示信息
     * @auther: wangyanwei
     * @date: 2019/9/24 9:13
     * @param paramName: 参数名称
     * @return: 
     */
    public static void paramIsNull(HttpServletResponse response, String paramName)  {
        RestResult restResult = new RestResult();
        restResult.setCode(ReturnCodeMsgEnum.PARAM_NOT_NULL.getCode());
        restResult.setMsg(paramName+ReturnCodeMsgEnum.PARAM_NOT_NULL.getMsg());
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json;charset=UTF-8");
        PrintWriter writer = null;
        try {
            writer = response.getWriter();
            writer.print(restResult);
        } catch (IOException e) {
             log.error("response error",e);
        } finally {
            if (writer != null) {

                writer.close();
            }
        }
    }
}
